/**
 * 中国象棋棋子定义和配置
 */

// 棋子类型枚举
export const PIECE_TYPES = {
  KING: 'king',       // 帅/将
  ADVISOR: 'advisor', // 仕/士
  ELEPHANT: 'elephant', // 相/象
  ROOK: 'rook',       // 车
  KNIGHT: 'knight',   // 马
  CANNON: 'cannon',   // 炮
  PAWN: 'pawn'        // 兵/卒
};

// 棋子颜色
export const COLORS = {
  RED: 'red',
  BLACK: 'black'
};

// 棋子定义
export const PIECES = {
  [COLORS.RED]: {
    '帥': { type: PIECE_TYPES.KING, value: 10000, symbol: '帥' },
    '仕': { type: PIECE_TYPES.ADVISOR, value: 20, symbol: '仕' },
    '相': { type: PIECE_TYPES.ELEPHANT, value: 20, symbol: '相' },
    '車': { type: PIECE_TYPES.ROOK, value: 90, symbol: '車' },
    '馬': { type: PIECE_TYPES.KNIGHT, value: 40, symbol: '馬' },
    '砲': { type: PIECE_TYPES.CANNON, value: 45, symbol: '砲' },
    '兵': { type: PIECE_TYPES.PAWN, value: 10, symbol: '兵' }
  },
  [COLORS.BLACK]: {
    '將': { type: PIECE_TYPES.KING, value: 10000, symbol: '將' },
    '士': { type: PIECE_TYPES.ADVISOR, value: 20, symbol: '士' },
    '象': { type: PIECE_TYPES.ELEPHANT, value: 20, symbol: '象' },
    '車': { type: PIECE_TYPES.ROOK, value: 90, symbol: '車' },
    '馬': { type: PIECE_TYPES.KNIGHT, value: 40, symbol: '馬' },
    '炮': { type: PIECE_TYPES.CANNON, value: 45, symbol: '炮' },
    '卒': { type: PIECE_TYPES.PAWN, value: 10, symbol: '卒' }
  }
};

// 棋子价值表
export const PIECE_VALUES = {
  [PIECE_TYPES.KING]: 10000,
  [PIECE_TYPES.ADVISOR]: 20,
  [PIECE_TYPES.ELEPHANT]: 20,
  [PIECE_TYPES.ROOK]: 90,
  [PIECE_TYPES.KNIGHT]: 40,
  [PIECE_TYPES.CANNON]: 45,
  [PIECE_TYPES.PAWN]: 10
};

// 位置价值表 - 用于AI评估
export const POSITION_VALUES = {
  [PIECE_TYPES.KING]: [
    [0, 0, 0, 8, 9, 8, 0, 0, 0],
    [0, 0, 0, 8, 9, 8, 0, 0, 0],
    [0, 0, 0, 8, 9, 8, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 8, 9, 8, 0, 0, 0],
    [0, 0, 0, 8, 9, 8, 0, 0, 0],
    [0, 0, 0, 8, 9, 8, 0, 0, 0]
  ],
  [PIECE_TYPES.ADVISOR]: [
    [0, 0, 0, 20, 0, 20, 0, 0, 0],
    [0, 0, 0, 0, 23, 0, 0, 0, 0],
    [0, 0, 0, 20, 0, 20, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 20, 0, 20, 0, 0, 0],
    [0, 0, 0, 0, 23, 0, 0, 0, 0],
    [0, 0, 0, 20, 0, 20, 0, 0, 0]
  ],
  [PIECE_TYPES.ELEPHANT]: [
    [0, 0, 20, 0, 0, 0, 20, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [18, 0, 0, 0, 23, 0, 0, 0, 18],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 20, 0, 0, 0, 20, 0, 0],
    [0, 0, 20, 0, 0, 0, 20, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [18, 0, 0, 0, 23, 0, 0, 0, 18],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 20, 0, 0, 0, 20, 0, 0]
  ],
  [PIECE_TYPES.ROOK]: [
    [206, 208, 207, 213, 214, 213, 207, 208, 206],
    [206, 212, 209, 216, 233, 216, 209, 212, 206],
    [206, 208, 207, 214, 216, 214, 207, 208, 206],
    [206, 213, 213, 216, 216, 216, 213, 213, 206],
    [208, 211, 211, 214, 215, 214, 211, 211, 208],
    [208, 212, 212, 214, 215, 214, 212, 212, 208],
    [204, 209, 204, 212, 214, 212, 204, 209, 204],
    [198, 208, 204, 212, 212, 212, 204, 208, 198],
    [200, 208, 206, 212, 200, 212, 206, 208, 200],
    [194, 206, 204, 212, 200, 212, 204, 206, 194]
  ],
  [PIECE_TYPES.KNIGHT]: [
    [90, 90, 90, 96, 90, 96, 90, 90, 90],
    [90, 96,103, 97, 94, 97,103, 96, 90],
    [92, 98, 99,103,  99,103, 99, 98, 92],
    [93,108,100,107,100,107,100,108, 93],
    [90,100, 99,103,104,103, 99,100, 90],
    [90,100, 99,103,104,103, 99,100, 90],
    [92, 94, 98, 95, 98, 95, 98, 94, 92],
    [93, 92, 94, 95, 92, 95, 94, 92, 93],
    [85, 90, 92, 93, 78, 93, 92, 90, 85],
    [88, 85, 90, 88, 90, 88, 90, 85, 88]
  ],
  [PIECE_TYPES.CANNON]: [
    [100, 100, 96, 91, 90, 91, 96, 100, 100],
    [98, 98, 96, 92, 89, 92, 96, 98, 98],
    [97, 97, 96, 91, 92, 91, 96, 97, 97],
    [96, 99, 99, 98,100, 98, 99, 99, 96],
    [96, 96, 96, 96,100, 96, 96, 96, 96],
    [95, 96, 99, 96,100, 96, 99, 96, 95],
    [96, 96, 96, 96, 96, 96, 96, 96, 96],
    [97, 96,100, 99,101, 99,100, 96, 97],
    [96, 97, 98, 98, 98, 98, 98, 97, 96],
    [96, 96, 97, 99, 99, 99, 97, 96, 96]
  ],
  [PIECE_TYPES.PAWN]: [
    [9, 9, 9, 11, 13, 11, 9, 9, 9],
    [19, 24, 34, 42, 44, 42, 34, 24, 19],
    [19, 24, 32, 37, 37, 37, 32, 24, 19],
    [19, 23, 27, 29, 30, 29, 27, 23, 19],
    [14, 18, 20, 27, 29, 27, 20, 18, 14],
    [7, 0, 13, 0, 16, 0, 13, 0, 7],
    [7, 0, 7, 0, 15, 0, 7, 0, 7],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0]
  ]
};

// 初始棋盘布局
export const INITIAL_BOARD = [
  // 第0行 - 黑方后排
  ['車', '馬', '象', '士', '將', '士', '象', '馬', '車'],
  // 第1行 - 空行
  [null, null, null, null, null, null, null, null, null],
  // 第2行 - 黑方炮（火字旁）
  [null, '炮', null, null, null, null, null, '炮', null],
  // 第3行 - 黑方卒
  ['卒', null, '卒', null, '卒', null, '卒', null, '卒'],
  // 第4行 - 空行
  [null, null, null, null, null, null, null, null, null],
  // 第5行 - 空行  
  [null, null, null, null, null, null, null, null, null],
  // 第6行 - 红方兵
  ['兵', null, '兵', null, '兵', null, '兵', null, '兵'],
  // 第7行 - 红方砲（石字旁）
  [null, '砲', null, null, null, null, null, '砲', null],
  // 第8行 - 空行
  [null, null, null, null, null, null, null, null, null],
  // 第9行 - 红方后排
  ['車', '馬', '相', '仕', '帥', '仕', '相', '馬', '車']
];
